home *** CD-ROM | disk | FTP | other *** search
- #define BASE_RES_ID 400
- #define NIL_POINTER 0L
- #define MOVE_TO_FRONT -1L
- #define REMOVE_ALL_EVENTS 0
- #define OVAL_WIDTH 20
- #define OVAL_HEIGHT 20
- #define PEN_WIDTH 1
- #define PEN_HEIGHT 1
- #define START_DEGREES 330
- #define ARC_DEGREES 60
-
-
- WindowPtr gDrawWindow;
- long gFillColor = blackColor;
-
- main()
- {
- ToolBoxInit();
- WindowInit();
- MainLoop();
- }
-
- ToolBoxInit()
- {
- InitGraf (&thePort);
- InitFonts();
- FlushEvents(everyEvent,REMOVE_ALL_EVENTS);
- InitWindows();
- InitMenus();
- TEInit();
- InitDialogs(NIL_POINTER);
- InitCursor();
- }
-
- WindowInit()
- {
- gDrawWindow = GetNewWindow( BASE_RES_ID, NIL_POINTER, MOVE_TO_FRONT);
- ShowWindow(gDrawWindow);
- SetPort(gDrawWindow);
- PenSize(PEN_WIDTH, PEN_HEIGHT);
- PenPat(black);
- }
-
- MainLoop()
- {
- GetDateTime(&randSeed);
- while(!Button())
- {
- DrawRandomRect();
- if(gFillColor==blackColor)
- gFillColor=whiteColor;
- else
- gFillColor=blackColor;
- }
- }
-
- DrawRandomRect()
- {
- Rect myRect;
-
- RandomRect(&myRect, gDrawWindow);
- ForeColor(gFillColor);
- PaintArc(&myRect, START_DEGREES, ARC_DEGREES);
- }
-
- RandomRect(myRectPtr,boundingWindow)
- Rect *myRectPtr;
- WindowPtr boundingWindow;
- {
- myRectPtr->left = Randomize(boundingWindow->portRect.right
- -boundingWindow->portRect.left);
- myRectPtr->right = Randomize(boundingWindow->portRect.right
- -boundingWindow->portRect.left);
- myRectPtr->top = Randomize(boundingWindow->portRect.bottom
- -boundingWindow->portRect.top);
- myRectPtr->bottom = Randomize(boundingWindow->portRect.bottom
- -boundingWindow->portRect.top);
- }
-
- Randomize (range)
- int range;
- {
- long rawResult;
- rawResult=Random();
- if(rawResult<0) rawResult *= -1;
- return((rawResult*range)/32768);
- }